<?php
namespace app\resources\tasks;

use base\map\Maps;
use app\admin\model\SystemLog;

// app('swoole.server')->task([ LogTask::class, $data ]);

// log 记录系统日志
class LogTask 
{

    protected $params = [];

    public function __construct($params=[])
    {
        $this->params = $params;
        $this->start($this->params);
    }

    // 
    public function start($data)
    {   
        // 获取ip区域
        $data['client_iparea'] = Maps::getIpArea( $data['client_ip'] );
        //保存记录 - 先删后插
        SystemLog::whereTime('create_time', '<', '-7 days')->delete();
        SystemLog::strict(false)->insert($data);
    }

}
